package com.moli.iov.down.command.design.factory;

import com.moli.iov.down.command.design.command.reshandler.ResponseHandlerCommand;
import com.moli.iov.down.command.design.command.reshandler.impl.*;
import com.moli.iov.protocol.enums.CommandTag;
import com.moli.iov.util.ByteUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 获取终端响应业务处理 命令模式 工厂
 * </p>
 *
 * @author: zql
 * @Date: 2018/12/29 17:57
 */
public class ReponseHandlerFactory {
    private static  final Logger logger = LoggerFactory.getLogger(ReponseHandlerFactory.class);

    private static final Map<Byte, ResponseHandlerCommand> RESPONSE_HANDLER_MAP = new HashMap<>();

    static {
        RESPONSE_HANDLER_MAP.put(CommandTag.REMOTE_CONTROL_RESPONSE.getV(), new RemoteControlCommand());
        RESPONSE_HANDLER_MAP.put(CommandTag.REMOTE_CONTROL_RESULT_RESPONSE.getV(), new RemoteControlResultCommand());
        RESPONSE_HANDLER_MAP.put(CommandTag.TERMINAL_PARAMETER_QUERY_RESPONSE.getV(), new TerminalParameterQueryCommand());
        RESPONSE_HANDLER_MAP.put(CommandTag.TERMINAL_PARAMETER_SETTING_RESPONSE.getV(), new TerminalParameterSettingCommand());
        RESPONSE_HANDLER_MAP.put(CommandTag.TERMINAL_CONTROL_RESPONSE.getV(), new TerminalControlCommand());
        RESPONSE_HANDLER_MAP.put(CommandTag.REMOTE_UPGRADE_RECV_RESPONSE.getV(), new UpgradeReceiveCommand());
        RESPONSE_HANDLER_MAP.put(CommandTag.REMOTE_UPGRADE_RESPONSE.getV(), new UpgradeCommand());
    }

    private ReponseHandlerFactory(){}

    public static ResponseHandlerCommand getResponseHandlerCommand(Byte commandTag){
        ResponseHandlerCommand responseHandlerCommand = RESPONSE_HANDLER_MAP.get(commandTag);
        if(responseHandlerCommand == null){

            String commandStr = ByteUtils.toHexString(commandTag);

            logger.error("获取终端响应业务处理对象 失败 命令：{}", commandStr);
        }
        return responseHandlerCommand;
    }
}
